home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / strategy / vga_card.000 / vga_cardgames-1.3.1.tar / vga_cardgames / mouse.c < prev    next >
C/C++ Source or Header  |  1995-02-26  |  2KB  |  114 lines

  1. /*
  2.  * Mouse handling
  3.  *
  4.  * Copyright (C) Evan Harris, 1994, 1995.
  5.  *
  6.  * Permission is granted to freely redistribute and modify this code,
  7.  * providing the author(s) get credit for having written it.
  8.  */
  9.  
  10. #include "vga16.h"
  11. #include "mouse.h"
  12.  
  13.  
  14. #define LIGHT 0
  15. #define DARK 1
  16.  
  17. #define MOUSE_IMAGE_PTS 37
  18.  
  19. struct mouse_image_data {
  20.     int x_offset;
  21.     int y_offset;
  22.     int colour;
  23. };
  24.  
  25. struct mouse_image_data mouse_image_data[MOUSE_IMAGE_PTS] = {
  26. { 0, 0, LIGHT },
  27. { 1, 0, LIGHT },
  28. { 2, 0, LIGHT },
  29. { 3, 0, LIGHT },
  30. { 4, 0, LIGHT },
  31. { 5, 0, LIGHT },
  32. { 0, 1, LIGHT },
  33. { 1, 1, DARK },
  34. { 2, 1, DARK },
  35. { 3, 1, LIGHT },
  36. { 0, 2, LIGHT },
  37. { 1, 2, DARK },
  38. { 2, 2, DARK },
  39. { 3, 2, LIGHT },
  40. { 4, 2, LIGHT },
  41. { 0, 3, LIGHT },
  42. { 1, 3, LIGHT },
  43. { 2, 3, LIGHT },
  44. { 3, 3, DARK },
  45. { 4, 3, LIGHT },
  46. { 5, 3, LIGHT },
  47. { 0, 4, LIGHT },
  48. { 2, 4, LIGHT },
  49. { 3, 4, LIGHT },
  50. { 4, 4, DARK },
  51. { 5, 4, LIGHT },
  52. { 6, 4, LIGHT },
  53. { 0, 5, LIGHT },
  54. { 3, 5, LIGHT },
  55. { 4, 5, LIGHT },
  56. { 5, 5, DARK },
  57. { 6, 5, LIGHT },
  58. { 7, 5, LIGHT },
  59. { 4, 6, LIGHT },
  60. { 5, 6, LIGHT },
  61. { 6, 6, LIGHT },
  62. { 5, 7, LIGHT },
  63. };
  64.  
  65.  
  66. void
  67. RenderMousePointer(int x, int y, int light, int dark, int width, int height)
  68. {
  69.     int i;
  70.     
  71.     for (i = 0; i < MOUSE_IMAGE_PTS; i++) {
  72.     if (x + mouse_image_data[i].x_offset < width &&
  73.         y + mouse_image_data[i].y_offset < height) {
  74.         if (mouse_image_data[i].colour == LIGHT) {
  75.         vga16_setpixel(light, x + mouse_image_data[i].x_offset,
  76.                    y + mouse_image_data[i].y_offset);
  77.         } else {
  78.         vga16_setpixel(dark, x + mouse_image_data[i].x_offset,
  79.                    y + mouse_image_data[i].y_offset);
  80.         }
  81.     }
  82.     }
  83. }
  84.  
  85.  
  86. void
  87. RestoreUnderMousePointer(int x, int y, int width, int height, int *colour)
  88. {
  89.     int i;
  90.  
  91.     for (i = 0; i < MOUSE_IMAGE_PTS; i++) {
  92.     if (x + mouse_image_data[i].x_offset < width &&
  93.         y + mouse_image_data[i].y_offset < height) {
  94.         vga16_setpixel(colour[i], x + mouse_image_data[i].x_offset,
  95.                y + mouse_image_data[i].y_offset);
  96.     }
  97.     }
  98. }
  99.  
  100.  
  101. void
  102. SaveUnderMousePointer(int x, int y, int width, int height, int *colour)
  103. {
  104.     int i;
  105.     
  106.     for (i = 0; i < MOUSE_IMAGE_PTS; i++) {
  107.     if (x + mouse_image_data[i].x_offset < width &&
  108.         y + mouse_image_data[i].y_offset < height) {
  109.         colour[i] = vga16_getpixel(x + mouse_image_data[i].x_offset,
  110.                        y + mouse_image_data[i].y_offset);
  111.     }
  112.     }
  113. }
  114.